//
//  CoolyViewController.m
//  YaDiuDiu
//
//  Created by 陈刚 on 2017/10/11.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "CoolyViewController.h"
#import "RentalDetailsTableViewCell.h"
#import "TBCycleView.h"

@interface CoolyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet TBCycleView *topCycleView;

@property (weak, nonatomic) IBOutlet UILabel *orderStatusLabel;

@property (weak, nonatomic) IBOutlet UIButton *cancelButton;

- (IBAction)cancelEvent:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITableView *coolyTable;

@end

@implementation CoolyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupView];
    
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}

- (void)setupView{
    [self showNav:@"订单详情"];
    [self.topCycleView.label setText:@"5:00"];
    [self.topCycleView drawProgress:0.5];
    
    [self.cancelButton.layer setMasksToBounds:YES];
    [self.cancelButton.layer setCornerRadius:5];
    [self.cancelButton.layer setBorderWidth:1];
    [self.cancelButton.layer setBorderColor:HexColorInt32_t(FD1142).CGColor];
    
    [self.coolyTable registerNib:[UINib nibWithNibName:@"RentalDetailsTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"Cell"];
}

- (void)loadData{
    NSString *ordertype = [self.detailsDic objectForKey:@"typeid"];
    
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSString *orderid = [self.detailsDic objectForKey:@"id"];
    
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setValue:token forKey:@"verifyToken"];
    [parmas setValue:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setValue:orderid forKey:@"orderid"];
    [parmas setValue:ordertype forKey:@"orderTypeId"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/UserOrder/userOrderDetails",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"用户查看订单列表res:%@",responseObject);
        NSInteger state = [[responseObject objectForKey:@"status"] integerValue];
        NSString *msg = [responseObject objectForKey:@"msg"];
        NSDictionary *dataDic = [responseObject objectForKey:@"content"];
        if (state  == 200 && [dataDic isKindOfClass:[NSDictionary class]]) {
            [SVProgressHUD dismiss];
            NSString *orderdenumber = [dataDic objectForKey:@"ordernumber"];
            NSString *addtime = [self getyYearsTimeFormat:[dataDic objectForKey:@"addtime"]];
            NSString *ordername = [dataDic objectForKey:@"ordername"];
            NSString *addressString = [NSString stringWithFormat:@"%@ %@ \n %@",[dataDic objectForKey:@"distname"],[dataDic objectForKey:@"disttel"],[dataDic objectForKey:@"distaddress"]];
           
            
        }else{
            [SVProgressHUD showErrorWithStatus:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *Identitfer  = @"Cell";
    RentalDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identitfer];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"RentalDetailsTableViewCell" owner:nil options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)cancelEvent:(UIButton *)sender {
}
@end
